package com.xyz.study.design_mode.t_flyweight.mode;

import java.util.HashMap;
import java.util.Map;

/**
 * role: Context 上下文
 * @author XYZ
 * @version 1.0.0
 * @since 2021/1/15
 */
public class PrinterFlyweightFactory {
    private static final Map<String, Printer> pool = new HashMap<>();

    public PrinterFlyweightFactory() {
        pool.put("linux", new PrinterLinux());
        pool.put("windows", new PrinterWindows());
    }

    /**
     * 获取对象
     * @param code code
     * @return {@link Printer}
     */
    public Printer getPrinter(String code){
        return pool.get(code);
    }
}
